package com.shangyitong.yygh_hosp.controller.api;

import com.shangyitong.Result;
import com.shangyitong.helper.HttpRequestHelper;
import com.shangyitong.yygh.model.hosp.Department;
import com.shangyitong.yygh_hosp.service.api.HospitalDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(value = "医院部门科室列表")
@RestController
@RequestMapping("/api/hosp")
@Slf4j
public class HospitalDepartmentController {

    @Autowired
    private HospitalDepartmentService hospitalDepartmentService;
    /**
     * 添加科室列表
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "添加科室列表")
    @PostMapping("saveDepartment")
    public Result saveDepartment(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        hospitalDepartmentService.saveDepartment(parameterMap);
        return Result.ok();
    }

    /**
     * 获取科室列表
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "获取科室列表")
    @PostMapping("department/list")
    public Result findDepartment(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Page<Department> departmentPage = hospitalDepartmentService.findDepartment(parameterMap);
        return Result.ok(departmentPage);
    }

    /**
     * 删除科室
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "删除科室")
    @PostMapping("department/remove")
    public Result removeDepartment(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        hospitalDepartmentService.removeDepartment(parameterMap);
        return Result.ok();
    }
}
